﻿using Corina.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Corina.Addins.Xiami
{
    public class DownloadInfo : BaseClass
    {
        private WebClient client = new WebClient();

        public DownloadInfo()
        {
            client.DownloadFileCompleted += DownloadFileCompleted;
            client.DownloadFileAsync(new Uri(Url), Directory + "//" + Filename);
        }

        public DownloadInfo(string filename, string url)
        {
            Filename = filename;
            Url = url;
            client.DownloadFileCompleted += DownloadFileCompleted;
            client.DownloadFileAsync(new Uri(Url), Directory + "//" + Filename);
        }

        private void DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            Completed = true;
        }

        public string Filename { get; set; }
        public string Url { get; set; }
        public string Directory
        {
            get { return Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); }
        }

        private bool _completed = false;
        public bool Completed
        {
            get { return _completed; }
            set {
                _completed = value;
                RaisePropertyChanged(() => Completed);
            }
        }
    }
}
